$(function(){
	$("#local_order_datagrid").datagrid({    
	    url:'customer/overseas_business/getAllLocalOrders.do', 
	    loadMsg:'数据加载中···',
	    fit:'true',
	    idField:'id',
	    pagination:true,
	    rownumbers:true,//行号  
	    checkOnSelect : true,
		selectOnCheck : true,
	    columns:[[
		{
			field : "id",
			hidden : true
		},     
	    {
			field:'customer_no',
			title:'客户编号',
			width:200,
			align:'center'
	    },    
	    {
	    	field:'order_no',
	    	title:'订单编号',
	    	width:200,
	    	align:'center'
	     },
	     {
	    	 field:'order_fee',
	    	 title:'订单费用(美金)',
	    	 width:120,
	    	 align:'center',
	    	 formatter:function(value, row, index){
	    		 if(row['state']==3){
	    			 return row['laborFee']+row['postage'];
	    		 }else{
	    			 return "--";
	    		 }
	    	 }
	    },
	     {
	    	 field:'business_type',
	    	 title:'订单业务类型',
	    	 width:170,
	    	 align:'center'
	    },{

	    	field:'state',
	    	title:'订单处理状态',
	    	width:110,
	    	align:'center',
	    	 formatter:function(value, row, index){
	    		 if(value==0)
	    			 return "待审核";
	    		 else if(value==1)
	    			 return "审核中";
	    		 else if(value==2)
	    			 return "备货中";
	    		 else if(value==3)
	    			 return "待付款";
	    		 else if(value==4)
	    			 return "发货中";
	    		 else if(value==5)
	    			 return "完成";
	    		 else
	    			 return "状态出错";
	    	 }
	    },
//	    {
//	    	 field:'image_name',
//	    	 title:'图片',
//	    	 width:180,
//	    	 align:'center',
//	    	 formatter:function(value,row,inedex){
//	    		 if(value==null || value==""){
//	    			 return "未上传";
//	    		 }else{
//	    			 return "<a target='_blank' href="+$("input[name='filePath3']").val()+value+">点击查看</a>"; 
//	    		 }
//	    		 
//	    	 }
//	    },
	    {
   	    	field:'create_tm',
   	    	title:'下单时间',
   	    	width:200,
   	    	align:'center',
   	        formatter: function(value,row,index){
   	        	return getTime(value);
   	        }},
   	     {

		    	field:'detail_check',
		    	title:'订单查看',
		    	width:100,
		    	align:'center', 
		    	formatter:function(value, row, index){
		    		//return "<a href='javascript:void(0)' onclick=\"showTransFiles("+index+")\">查看详情</a>";
		    		return "<a href='javascript:void(0)' onclick=\"showLocalDetail('"+row.order_no+"')\">查看详情</a>";
		    	}
		    },
	     {
	    	 field:'order_pay',
	    	 title:'付款',
	    	 width:100,
	    	 align:'center',
	   	        formatter: function(value,row,index){
	   	        	if(row.state==3){
	   	        		return "<a style='color:red' target='_blank' href='https://auth.alipay.com/login/index.htm'>支付宝</a>|"+
	   	        		"<a style='color:red' target='_blank' href='https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=PQPQJNXGSLLNN'>PayPal</a>";
	   	        	}else{
	   	        		return "--";
	   	        	}
	   	   },
	     }
	    ]],
	    fitColumns:true
	});  	
});
function showLocalDetail(order_no){
	$("#local_detail_dialog").dialog({    
	    title: '查看订单详情',    
	    width: 650,   
	    height: 500,
	    closed: false,    
	    cache: false,
	    iconCls:'icon-eye',
	    href: 'customer/overseas_business/show_local_detail?order_no='+order_no,    
	    modal: true,
	    buttons:[{
			text:'关闭',
			handler:function(){
				$("#local_detail_dialog").dialog('close');
				$("#local_order_datagrid").datagrid('uncheckAll');
			}
		}]      
	});    
}
function getTime(old) {
	var date = new Date(old);
	var year = date.getFullYear();
	var month = date.getMonth() + 1;
	if (month < 10)
		month = "0" + month;
	var day = date.getDate();
	if (day < 10)
		day = "0" + day;
	var hour = date.getHours();
	if (hour < 10)
		hour = "0" + hour;
	var minute = date.getMinutes();
	if (minute < 10)
		minute = "0" + minute;
	var seconds = date.getSeconds();
	if (seconds < 10)
		seconds = "0" + seconds;
	var newDate = year + "-" + month + "-" + day + " " + hour + ":" + minute
			+ ":" + seconds;
	return newDate;
}
/**查询条件*/
function queryLocal(){
	$("#local_order_datagrid").datagrid({
		queryParams: {
			orderNo: $("input[name='localOrderNo']").val(),
			tmFrom : $("input[name='localTmFrom']").val(),
			tmTo : $("input[name='localTmTo']").val()
		}
	});
}
function resetLocal(){
	$("input[name='localOrderNo']").val("");
	$("input[name='localTmFrom']").val("");
	$("input[name='localTmTo']").val("");
	$("#localTmFrom").datebox("setValue","");
	$("#localTmTo").datebox("setValue","");
	queryLocal();
}
